//
//  WQDateTool.m
//  WQDateTool
//
//  Created by Xiang on 2021/5/22.
//

#import "WQDateTool.h"

@implementation WQDateTool

//日期格式字符串转为NSDate类型
+ (NSDate *)wqDateFromString:(NSString *)string{
    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date = [dateFormatter dateFromString:string];
    return date;
}

//时间戳转为NSDate类型
+ (NSDate *)wqDateFromTimeInt:(NSTimeInterval)timeInt{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInt];
    return date;
}


//Date类型转为日期格式字符串
+ (NSString *)wqStringFromDate:(NSDate *)date{
    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    dateFormatter.timeZone=[NSTimeZone defaultTimeZone];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *str = [dateFormatter stringFromDate:date];
    return str;
}

//时间戳类型转为日期格式字符串
+ (NSString *)wqStringFromTimeInt:(NSTimeInterval)timeInt{
    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    dateFormatter.timeZone=[NSTimeZone defaultTimeZone];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInt];
    NSString *str = [dateFormatter stringFromDate:date];
    return str;
}


//日期格式字符串转为时间戳类型
+ (NSTimeInterval)wqTimeIntervalFromString:(NSString *)string{
    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    dateFormatter.timeZone=[NSTimeZone defaultTimeZone];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date = [dateFormatter dateFromString:string];
    NSTimeInterval dateTimeInterval = [date timeIntervalSince1970];
    return dateTimeInterval;
}

//日期格式字符串转为时间戳类型
+ (NSTimeInterval)wqTimeIntervalFromDate:(NSDate *)date{
    NSTimeInterval timeInterva = [date timeIntervalSince1970];
    return timeInterva;
}

@end
